:Init
@rem Define variables

set __version=0.0.0.3
set __packmode=jsmin
set __binariespath=.\packed\
set __filenames=
set __chkpackagename=nt.chk.js
set __frepackagename=nt.fre.js
set __finalpackagename=nt.js

@rem #######################################

@rem add commands

if %1==chk goto ChkBuild
if %1==fre goto FreBuild
if %1==doc goto DocBuild

:ChkBuild

del %__binariespath%%__chkpackagename%
del  %__binariespath%%__finalpackagename%


for /f %%f in (BuildList.txt) do call AppendSource.bat %%f %__binariespath%%__chkpackagename%

copy ".\BOM"+"%__binariespath%%__chkpackagename%" "%__binariespath%%__finalpackagename%" /B

goto CleanUp

:FreBuild

for /f %%f in (BuildList.txt) do set __filenames=!__filenames! %%f 
%__binariespath%Packer.exe -o %__binariespath%%__frepackagename% -m %__packmode% %__filenames%

copy ".\BOM"+"%__binariespath%%__frepackagename%" "%__binariespath%%__finalpackagename%" /B

goto CleanUp

:DocBuild

del %__binariespath%%__chkpackagename% /q
del %__binariespath%%__frepackagename% /q
del %__binariespath%%__finalpackagename% /q

call CreateDocs.bat

goto CleanUp

:CleanUp

@rem Write version number

echo ; >> %__binariespath%%__finalpackagename%
echo __version = "%__version%"; >> %__binariespath%%__finalpackagename%

set __version=
set __filenames=
set __packmode=
set __binariespath=
set __chkpackagename=
set __frepackagename=
